Memcached 1.5.12 Porting Guide (openEuler 20.03 LTS SP1)

randy15682021-12-29MemcachedPorting Guide

Introduction

Overview

Memcached is a high-performance, distributed memory object caching server, developed by Brad Fitzpatric from Danga Interactive, a subsidiary of LiveJournal. It is used to cache database query results and reduce database access times to improve the speed and scalability of dynamic web applications.

Official Memcached website: https://memcached.org/

Programming language: C

Brief description: distributed memory object caching system

Environmental Requirements

Hardware

The following table lists the hardware requirements.

ItemDescription
ServerTaiShan 200 server (model 2280)
CPUKunpeng 920 5250 processor
Drive partitionNo requirements

Operating Systems

The following table lists the requirements for the operating system.

ItemVersion
openEuler20.03 LTS SP1 AArch64
Kernel4.19

Check the current OS version.

cat /etc/os-release

For details about installing the openEuler OS, see https://docs.openeuler.org/en/docs/20.03_LTS_SP1/docs/Installation/Installation.html.
Note: You are advised to select the "Server with GUI" installation mode.

Configuring the Compilation Environment

To compile Memcached, you need to prepare the C compiler, GNU, make, automake, libevent, and libevent-devel.

  1. Install the GNU Compiler Collection (GCC). If GCC has been installed, skip this step.

    bash
    yum -y install gcc gcc-c++ kernel-devel
  2. Install GNU make, Automake, unzip, and Telnet. If they have been installed, skip this step.

    bash
    yum -y install make automake unzip telnet
  3. Install libevent and libevent-devel.

    bash
    yum -y install libevent libevent-devel

Obtaining Source Code

If your server can access the network, run the "wget https://github.com/memcached/memcached/archive/1.5.12.zip" command to download the source code. Otherwise, visit https://github.com/memcached/memcached/archive/1.5.12.zip to download the source code and copy it to the /home directory on the server.

Compiling and Installing Memcached

The following uses the source code downloaded to the local PC and then uploaded to the server as an example for describing compilation and installation operations.

  1. Decompress the source package.

    bash
    cd /home
    bash
    unzip 1.5.12.zip
  2. Go to the memcached-1.5.12 directory.

    bash
    cd memcached-1.5.12
  3. Configure Memcached.

    bash
    sh autogen.sh
    bash
    ./configure --prefix=/opt/memcached

    You can specify the Memcached installation directory, for example, /opt/memcached, in this step.

  4. Perform compilation.

    bash
    make -j60

    -j60 leverages the multi-core CPUs to speed up compilation.

  5. Perform installation.

    bash
    make install
  6. Switch to the Memcached installation directory /opt/memcached. If the generated bin directory contains the Memcached executable file, installation is successful.

  7. Set environment variables.

    a. Add the following command to the /etc/profile file:

    bash
    export PATH=/opt/memcached/bin/:$PATH

    b. Make the environment variable effective.

    bash
    source /etc/profile

Running and Verifying Memcached

  • Start Memcached.

    bash
    memcached -t 24 -p 11211 -u root -m 49152 -c 10240

    The following table describes the parameters in the startup command.

ParameterDescriptionDefault Value
-tThread count4
-pTCP listening port11211
-uUser who starts the processThe default user cannot be root.
-mMemory size (in MB) allocated to Memcached64M
-cMaximum number of concurrent connections1024
-dStarts a daemon in the background.-
  • Start another shell window to connect to Memcached.

    bash
    telnet 127.0.0.1 11211
  • After creating a connection, run the stats command to obtain the statistics of the Memcached server.

    bash
    stats

The following table lists the common stats commands.

CommandDescription
statsDisplays the overall status of Memcached, including the startup time, amount of data stored, cache hit ratio, and number of current connections.
stats itemsOutputs the item information of each slab.
stats slabsOutputs more details about slabs.
stats sizesDisplays the size and number of all items.
stats cachedumpOutputs certain pieces of data in a slab. If the input is 0, all data in the slab is output.
stats detailSets (on/off) or displays (dump) detailed operation records, such as the get/set operation.
flush_allInvalidates all items in the memory. This operation does not suspend the server because no free memory is released and the existing items are marked as invalid.

Note: To exit the Telnet connection, run the quit command.

bash
quit

In addition to connecting to the Memcached service using Telnet to obtain data, the source code provides some tool scripts, such as memcached-tool, in the scripts directory of the source code.

For details about how to use the memcached-tool, see the following table.

CommandDescription
./memcached-tool localhost displayDisplays slabs information.
./memcached-tool 10.0.0.5:11211 displayDisplays slabs information.
./memcached-tool 10.0.0.5:11211 statsDisplays memcached statistics.
./memcached-tool 10.0.0.5:11211 settingsDisplays memcached settings.
./memcached-tool 10.0.0.5:11211 sizesDisplays the size and number of all items.
./memcached-tool 10.0.0.5:11211 dump [limit]Outputs keys and values from the cache.

[Disclaimer] This article only represents the author's opinions, and is irrelevant to this website. This website is neutral in terms of the statements and opinions in this article, and does not provide any express or implied warranty of accuracy, reliability, or completeness of the contents contained therein. This article is for readers' reference only, and all legal responsibilities arising therefrom are borne by the reader himself.